import request from '../utils/request';
import {Register} from "@/types/user";


export interface LoginResponse {
    code: number;
    msg: string;
    data: {
        user: {
            id: number;
            username: string;
            password: string; // 这通常不应返回
            role: string;
        };
        token: string;
    };
}
interface RegisterResponse {
    code: number;
    msg: string;
    data?: any;   // 可选的返回数据
}

export const loginUser = async (username: string, password: string): Promise<LoginResponse> => {
    return await request({
        url: '/api/login',
        method: 'post',
        data: {username, password},
    }); // 返回整个响应
};

export const registerUser = async (register: Register): Promise<RegisterResponse> => {
    return await request({
        url: '/api/register',
        method: 'post',
        data: register,
    });
};

